package problems.daily;

import java.util.Arrays;

/**
 * @author habitplus
 * @since 2023/3/22 9:45
 */
public class DT1626 {

    // 动态规划
    public int bestTeamScore(int[] scores, int[] ages) {
        int n = scores.length;
        int[][] arr = new int[n][2];

        for (int i = 0; i < n; ++i) {
            arr[i][0] = scores[i];
            arr[i][1] = ages[i];
        }

        Arrays.sort(arr, (o1, o2) -> o1[0] == o2[0] ? o1[1] - o2[1] : o1[0] - o2[0]);

        int[] dp = new int[n];
        int ans = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = i - 1; j >= 0; --j) {
                if (arr[j][1] <= arr[i][1]) {
                    dp[i] = Math.max(dp[i], dp[j]);
                }
            }
            dp[i] += arr[i][0];
            ans = Math.max(ans, dp[i]);
        }
        return ans;
    }


}
